// Copyright (C) 2011 YANG Hao (yangh2007@gmail.com). All rights reserved.
//
// This file is part of the (cute)octopus project.
//
// This file may be distributed and/or modified under the terms of the
// GNU General Public License version 2 as published by the Free Software
// Foundation.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Author(s): YANG Hao


#ifndef OFORMAT_H
#define OFORMAT_H

#include <QIcon>
#include <QString>
#include <QFileInfo>
#include <QObject>

#include "ostd.h"

class ODocDescriptor  
{
public:
	ODocDescriptor(const QString& name, const QString& description, 
		const QIcon& icon, const QStringList& suffices, const QByteArray& format)
		: m_name(name), m_description(description), m_icon(icon), m_suffices(suffices), m_format(format){}
	ODocDescriptor(const ODocDescriptor& f)
		: m_name(f.m_name), m_description(f.m_description), m_icon(f.m_icon), m_suffices(f.m_suffices){}
	~ODocDescriptor(){}

	inline QString name() const {return m_name;}
	inline QString description() const {return m_description;}
	inline QIcon icon() const {return m_icon;}
	inline QString filter() const {return m_name + (" (*.") + (m_suffices.join(" *.")) + (")");}
	inline QStringList suffices() const {return m_suffices;}
	inline bool support(const QString& suffix) const {return m_suffices.contains(suffix);}
	inline QString unnamedSample() const {
		static qint64 _INDEX = 0; 
		return (++_INDEX) == 1 ? 
			QObject::tr("Unnamed.")+m_suffices.first()
			: QObject::tr("Unnamed-%1.").arg(_INDEX)+m_suffices.first();
	}
	inline const char* format() const {return m_format.data();}

private:
	const QString m_name;
	const QString m_description;
	const QIcon m_icon;
	const QStringList m_suffices;
	const QByteArray m_format;
};

typedef QList<ODocDescriptor*> OFileDescriptorList;

template <typename _CLASS_>
class ODescriptor
{
public:
	_CLASS_* createInstance() const {return 0;}
	QString name() const {return m_name;}
	QString infomation() const {return m_infomation;}
	QIcon icon() const {return m_icon;}

private:
	const QString m_name;
	const QString m_infomation;
	const QIcon m_icon;
};


#endif // OFORMAT_H
